package fr.pud.client.controller.query;

import java.awt.event.ActionEvent;
import java.util.Set;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import fr.pud.client.i18n.LanguagesConstants;
import fr.pud.client.images.ImagesDatabase;
import fr.pud.client.model.Queries;
import fr.pud.client.model.Query;
import fr.pud.client.view.MainFrame;
import fr.pud.utils.Tools;

/**
 * Apr 10, 2012 - tsp-osmOSE.
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 *         Ecole des Mines de Nantes
 *         SaveQueries.java
 */
public class SaveQueries extends AbstractAction {
    /**
     * 
     */
    private static final long serialVersionUID = 8159826967530415914L;

    /**
     * Default constructor
     */
    public SaveQueries() {
        this.putValue(NAME, LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.SAVE_QUERIES));
        this.putValue(SHORT_DESCRIPTION, LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.SAVE_QUERIES));
        this.putValue(SMALL_ICON, ImagesDatabase.SAVE);
    }

    /*
     * (non-Javadoc)
     * @see
     * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    @Override
    public void actionPerformed(ActionEvent arg0) {
        String fileName = JOptionPane.showInputDialog(MainFrame.getSingleton(),
                LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.INPUT_FILE_NAME),
                LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.SAVE_QUERIES),
                JOptionPane.PLAIN_MESSAGE);
        Set<Query> queries = Queries.getInstance().getQueries();
        Tools.saveObject(queries, fileName, LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.QUERIES).toLowerCase());
    }
}
